﻿using System;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace ShenLanCMS.Models
{
    /// <summary>
    /// 广告实体
    /// </summary>
    public class Ad
    {
        [System.ComponentModel.DataAnnotations.Key]
        public Guid AdID { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        [Display(Name = "标题")]
        [StringLength(32,ErrorMessage="{0}不能超过{1}个字符")]
        public string Title { get; set; }

        /// <summary>
        /// 类型id
        /// </summary>
        [Display(Name = "类型")]
        public Guid AdTypeID { get; set; }

        /// <summary>
        /// 广告内容
        /// </summary>
        [Required(ErrorMessage="请填写{0}")]
        [DataType(DataType.MultilineText)]
        [Display(Name = "广告内容")]        
        [StringLength(8192,ErrorMessage="广告内容不能超过{1}个字符")]
        public string Content { get; set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        [Display(Name = "开始时间")]
        public DateTime? StartTime { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        [Display(Name = "结束时间")]
        public DateTime? EndTime { get; set; }

        /// <summary>
        /// 宽
        /// </summary>
        [Display(Name = "宽")]
        public int Width { get; set; }

        /// <summary>
        /// 高
        /// </summary>
        [Display(Name = "高")]
        public int Height { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        [Display(Name = "是否启用")]
        public bool IsEnable { get; set; }

        /// <summary>
        /// 获取该广告的类型 
        /// </summary>
        /// <returns></returns>
        public AdType GetAdType()
        {
            var db = new ShenLanCMS.Models.EntityContext();
            var at = db.AdTypes.SingleOrDefault(n => n.AdTypeID == this.AdTypeID);
            if (at == null)
                at = new AdType();
            return at;
        }
    }
}
